package com.jiazhong.service.safty.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.jiazhong.base.CurrUser;
import com.jiazhong.dao.safty.LoginDao;
import com.jiazhong.exception.LoginException;
import com.jiazhong.exception.SysException;
import com.jiazhong.model.User;
import com.jiazhong.service.safty.LoginService;
import com.jiazhong.view.UserView;
@Service
@Transactional
public class LoginServiceImpl implements LoginService {
	@Autowired
	private LoginDao loginDao;
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	@Override
	public CurrUser login(UserView userView) {
		User user = null;
		try {
			user = loginDao.login(userView);
		}catch (Exception e) {
			//出现异常
			throw new SysException("系统错误!");
		}
		if(user==null) {//登录失败，抛出异常
			throw new LoginException("用户名或密码错误!");
		}
		//登录成功，返回CurrUser对象
		return new CurrUser(user.getU_id(),user.getU_name());
	}

}
